package demo.practice.binary_search;

public class P50_2 {


    public static void main(String[] args) {
        P50_2 p50_2 = new P50_2();
        double v = p50_2.myPow(2.00000, 10);
        System.out.println(v);

    }

    public double myPow(double x, int n) {
        if (n == 0)
            return 1.0;
        long b = n;
        //boolean ne = b < 0;//是负数
        x = b < 0 ? 1 / x : x;
        b = Math.abs(b);

        double res = 1;
        while (b > 0) {
            if ((b & 1) == 1) {
                res = res * x;
                b--;
            } else {
                x *= x; //叠乘
                b >>= 1;
            }
        }
        //return ne ? 1 / res : res;
        return res;
    }

}
